﻿using System.Data.Services;

namespace AstoriaPlus
{
	public interface IEntityInterceptorFactory<TDataService, TDataSource>
		where TDataService : DataService<TDataSource>
		where TDataSource : class
	{
		IEntityInterceptor<TDataService, TDataSource> Create();
	}

	public interface IEntityInterceptorFactory<TDataService, TDataSource, TEntity> : IEntityInterceptorFactory<TDataService, TDataSource>
		where TDataService : DataService<TDataSource>
		where TDataSource : class
		where TEntity : class
	{
		IEntityInterceptor<TDataService, TDataSource, TEntity> Create();
	}

	public class DefaultEntityInterceptorFactory<TDataService, TDataSource, TEntity, TEntityInterceptor> : IEntityInterceptorFactory<TDataService, TDataSource, TEntity>
		where TDataService : DataService<TDataSource>
		where TDataSource : class
		where TEntity : class
		where TEntityInterceptor : IEntityInterceptor<TDataService, TDataSource, TEntity>, new()
	{
		public virtual IEntityInterceptor<TDataService, TDataSource, TEntity> Create()
		{
			return new TEntityInterceptor();
		}

		IEntityInterceptor<TDataService, TDataSource> IEntityInterceptorFactory<TDataService, TDataSource>.Create()
		{
			return this.Create();
		}
	}

	public class DefaultEntityInterceptorFactory<TDataService, TDataSource, TEntityInterceptor> : IEntityInterceptorFactory<TDataService, TDataSource>
		where TDataService : DataService<TDataSource>
		where TDataSource : class
		where TEntityInterceptor : IEntityInterceptor<TDataService, TDataSource>, new()
	{
		public virtual IEntityInterceptor<TDataService, TDataSource> Create()
		{
			return new TEntityInterceptor();
		}
	}
}
